var selectMonth = '\
    <select id="showMonth" name="showMonth" onchange="getMonthNum()" style="border: 0px;width: 60px;">\
	<option value="1">1月</option>\
	<option value="2">2月</option>\
	<option value="3">3月</option>\
	<option value="4">4月</option>\
	<option value="5">5月</option>\
	<option value="6">6月</option>\
	<option value="7">7月</option>\
	<option value="8">8月</option>\
	<option value="9">9月</option>\
	<option value="10">10月</option>\
	<option value="11">11月</option>\
	<option value="12">12月</option>\
</select>\
';
var flagDate = undefined;
var reviewedRecordData = undefined;
var reviewRecordData = undefined;
var reviewLineIDData = undefined;
var indexFlag = undefined;
var reviewMan = undefined;
var HintNum = undefined;
var lineIDList = [];
var chargingStationIDList = [];

$(document).ready(function() {
	showLoading();
	setBaseUrl();
	$('title', parent.document).html($('title').text());
	createTableHead("lineReviewThead", lineReviewTable);
	$ajaxList('branchCompany', getBranchCompany);
	monthChange(0);
});
function getMonthNum(){
	var num = $("#showMonth").val();
	monthChange(parseInt(num));
}
function getBranchCompany(data) {
	var length = data.length;
	for (var i = 0;i < length; i++){
    	branchCompanyData = data;
        $("#branchCompanyID").append("<option value='" + data[i].branchCompanyID + "'>" + data[i].branchCompanyName + "</option>");
    }
	$("#branchCompanyID").val("2");
	changeBranch();
}
function changeBranch() {
	var branchCompanyID = $("#branchCompanyID").val();
	if (branchCompanyID) {
		$("#changeSubBranch").show();
		$("#SubBranchCompanyID").empty();
		$("#changeTeam").hide();
		$("#TeamID").empty();
		$("#changeLine").hide();
		$("#LineID").empty();
		$("#TeamID").append("<option value=''>请选择</option>");
		$ajaxList('subBranchCompany', getSubBranchCompanyList, {"branchCompanyID": branchCompanyID});
	} else {
		$("#changeSubBranch").hide();
		$("#SubBranchCompanyID").empty();
		$("#changeTeam").hide();
		$("#TeamID").empty();
		$("#changeLine").hide();
		$("#LineID").empty();
	}
}
function getSubBranchCompanyList(data) {
	$("#SubBranchCompanyID").empty();
	$("#SubBranchCompanyID").append("<option value=''>请选择</option>");
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#SubBranchCompanyID").append("<option value='" + data[i].subBranchCompanyID + "'>" + data[i].subBranchCompanyName + "</option>");
	}
}
function changeCarTeam(){
	var subBranchCompanyID = $("#SubBranchCompanyID").val();
	if (subBranchCompanyID) {
		$("#changeTeam").show();
		$("#TeamID").empty();
		$("#changeLine").hide();
		$("#LineID").empty();
		$("#TeamID").append("<option value=''>请选择</option>");
		$ajaxList('carTeam', getCarTeamList, {"subBranchCompanyID": subBranchCompanyID});
	} else {
		$("#changeTeam").hide();
		$("#TeamID").empty();
		$("#changeLine").hide();
		$("#LineID").empty();
	}
}
function getCarTeamList(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#TeamID").append("<option value='" + data[i].teamID + "'>" + data[i].teamName + "</option>");
	}
}
function changeLine(){
	var teamID = $("#TeamID").val();
	var subBranchCompanyID = $("#SubBranchCompanyID").val();
	if (teamID) {
		$("#changeLine").show();
		$("#LineID").empty();
		$("#LineID").append("<option value=''>请选择</option>");
		$ajaxList('lineName', getLineNameList, {"teamID": teamID, "subBranchCompanyID": subBranchCompanyID});
	} else {
		$("#changeLine").hide();
		$("#LineID").empty();
	}
}
function getLineNameList(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#LineID").append("<option value='" + data[i].lineID + "'>" + data[i].lineName + "</option>");
	}
}
function search(){
	$("#reviewDate").val($("#startChargingTime").val().substring(0,10));
	$ajax('searchReviewedRecord', 'lineReviewSearch', searchReviewedRecord);
}
function searchReviewedRecord(data) {
	reviewedRecordData = data && data.reviewedRecordList || [];
	clearTable("lineReviewTbody");
	var tbody = $("#lineReviewTbody");
	lineIDList = [];
	chargingStationIDList = [];
	for(var i = 0; i < reviewedRecordData.length; i++) {
		lineIDList.push(reviewedRecordData[i].lineID);
		chargingStationIDList.push(reviewedRecordData[i].chargingStationID);
		$tr = $('<tr>').appendTo(tbody);
		$("<td>").html(i + 1).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].chargingStationName).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].subBranchCompanyName).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].teamName).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].lineName).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].chargingCount).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].sumChargingKWH).appendTo($tr);
		$("<td>").html(reviewedRecordData[i].remarks).appendTo($tr);
		if(reviewedRecordData[i].reviewState == "1") {
			$("<td class='auditorHintTD'>").html("等待车队确认  <div class='HintImgDiv' onMouseOver='showHint(\""+ i +"\");' onMouseOut='hideHint(\""+ i +"\");'><img src='static/images/auditorHint.png'/>"
					+ "<div class='auditorHintDiv' id='Hint"+ i +"div' hidden='hidden' onMouseOver='showHint(\""+ i +"\");' onMouseOut='hideHint(\""+ i +"\");'>" +
							"<div class='HintTriangleOne'><div class='HintTriangleTwo'></div></div>" +
							"<div class='HintMessage'>" +
							"<div style='color:#c5c1c1'>车队负责人信息</div>" +
							"<div id='Hint"+ i +"'>-</div>" +
							"</div>" +
							"</div>"
			).appendTo($tr);
			$("<td>").html(reviewedRecordData[i].reviewPerson).appendTo($tr);
			$("<td>").html('<span onclick="review('+ i +')" class="bacLightGreen details operationWord" style="color: white;">重新审核</span>').appendTo($tr);
			if(reviewedRecordData[i].reviewWay == "charging") {
				$('<td id="reviewFile' + i + '">').html("").appendTo($tr);
			} else {
				if(reviewedRecordData[i].reviewFile != null) {
					$('<td id="reviewFile' + i + '">').html('<span onclick="downLoad('+ i +')" class="bacLightGreen details operationWord" style="color: white;">查看</span>').appendTo($tr);
				} else {
					$('<td id="reviewFile' + i + '">').html('<span onclick="upLoad('+ i +')" class="bacLightGreen details operationWord" style="color: white;">上传</span>').appendTo($tr);
				}
			}
		} else {
			$("<td>").html("车队确认").appendTo($tr);
			$("<td>").html(reviewedRecordData[i].reviewPerson).appendTo($tr);
			$("<td>").html("审核完成").appendTo($tr);
			if(reviewedRecordData[i].reviewWay == "charging") {
				$('<td id="reviewFile' + i + '">').html("").appendTo($tr);
			} else {
				if(reviewedRecordData[i].reviewFile != null) {
					$('<td id="reviewFile' + i + '">').html('<span onclick="downLoad('+ i +')" class="bacLightGreen details operationWord" style="color: white;">查看</span>').appendTo($tr);
				} else {
					$('<td id="reviewFile' + i + '">').html("查阅手抄记录").appendTo($tr);
				}
			}
		}
	}
	searchReviewed();
}
function searchReviewed(){
	if(reviewedRecordData && reviewedRecordData.length == 0) {
		$("#reviewDate").val("");
	}
	$("#lineIDList").val(lineIDList.toString());
	$("#chargingStationIDList").val(chargingStationIDList.toString());
	$ajax('searchReviewRecord', 'lineReviewSearch', searchReviewRecord);
}
function searchReviewRecord(data){
	reviewRecordData = data && data.reviewRecordList || [];
	reviewLineIDData = data && data.reviewLineIDList || [];
	var tbody = $("#lineReviewTbody");
	for(var i = 0; i < reviewRecordData.length; i++) {
		$tr = $('<tr>').appendTo(tbody);
		$("<td>").html(i + 1).appendTo($tr);
		$("<td>").html(reviewRecordData[i].chargingStationName).appendTo($tr);
		$("<td>").html(reviewRecordData[i].subBranchCompanyName).appendTo($tr);
		$("<td>").html(reviewRecordData[i].teamName).appendTo($tr);
		$("<td>").html(reviewRecordData[i].lineName).appendTo($tr);
		$("<td>").html(reviewRecordData[i].chargingCount).appendTo($tr);
		$('<td id="chargingKWH' + i + '">').html(reviewRecordData[i].sumChargingKWH + '<img src="static/images/detalisUpdate.png" onclick="changeChargingKWH(' + i + ')">').appendTo($tr);
		$('<td id="remark'+ i +'">').html('<input id="remarks' + i + '" style="text-align: center;">').appendTo($tr);
		$('<td id="reviewFlag' + i + ' class="auditorHintTD">').html("<span id='sureOld" + i + "'>未审核</span>").appendTo($tr);
		$('<td id="reviewMan'+ i +'">').html('<input id="reviewPerson' + i + '" style="text-align: center;width: 100px;" value="' + $("#userName", parent.document).html() + '">').appendTo($tr);
		$('<td id="reviewState'+ i +'">').html('<span onclick="reviewState('+ i +')" class="bacLightGreen details operationWord" style="color: white;">审核</span>').appendTo($tr);
		$('<td id="reviewFile' + i + '">').html("").appendTo($tr);
	}
	for(var i = 0; i < reviewLineIDData.length; i++) {
		$tr = $('<tr>').appendTo(tbody);
		$("<td>").html(i + 1).appendTo($tr);
		$("<td>").html(reviewLineIDData[i].chargingStationName).appendTo($tr);
		$("<td>").html(reviewLineIDData[i].subBranchCompanyName).appendTo($tr);
		$("<td>").html(reviewLineIDData[i].teamName).appendTo($tr);
		$("<td>").html(reviewLineIDData[i].lineName).appendTo($tr);
		$("<td>").html(reviewLineIDData[i].chargingCount).appendTo($tr);
		$('<td id="chargingKWHNone' + i + '">').html(reviewLineIDData[i].sumChargingKWH + '<img src="static/images/detalisUpdate.png" onclick="changeChargingKWHNone(' + i + ')">').appendTo($tr);
		$('<td id="remarkNone'+ i +'">').html('<input id="remarksNone' + i + '" style="text-align: center;">').appendTo($tr);
		$('<td id="reviewFlagNone' + i + ' class="auditorHintTD">').html("<span id='sureOldNone" + i + "'>未审核</span>").appendTo($tr);
		$('<td id="reviewManNone'+ i +'">').html('<input id="reviewPersonNone' + i + '" style="text-align: center;width: 100px;" value="' + $("#userName", parent.document).html() + '">').appendTo($tr);
		$('<td id="reviewStateNone'+ i +'">').html('<span onclick="reviewStateNone('+ i +')" class="bacLightGreen details operationWord" style="color: white;">审核</span>').appendTo($tr);
		$('<td id="reviewFileNone' + i + '">').html("").appendTo($tr);
	}
}
function changeChargingKWH(index) {
	$("#chargingKWH" + index).html('<input id="sumChargingKWH' + index + '" value="' + reviewRecordData[index].sumChargingKWH + '" style="text-align: center;">');
}
function changeChargingKWHNone(index) {
	$("#chargingKWHNone" + index).html('<input id="sumChargingKWHNone' + index + '" value="' + reviewLineIDData[index].sumChargingKWH + '" style="text-align: center;">');
}
function reviewState(index) {
	if(!$("#startChargingTime").val()) {
		showMessge("时间错误，请刷新页面重试");
	} else if(!reviewRecordData[index].chargingCount) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewRecordData[index].chargingStationName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewRecordData[index].lineName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewRecordData[index].subBranchCompanyName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewRecordData[index].sumChargingKWH) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewRecordData[index].teamName) {
		showMessge("数据错误，请刷新页面重试");
	} else {
		indexFlag = index;
		var sumChargingKWH = 0;
		var reviewWay = "charging";
		var totalChargingKWH = 0;
		if($("#sumChargingKWH" + index).val() && reviewRecordData[index].sumChargingKWH != $("#sumChargingKWH" + index).val()) {
			reviewWay = "entering";
			sumChargingKWH = $("#sumChargingKWH" + index).val();
			totalChargingKWH = reviewRecordData[index].sumChargingKWH;
		} else {
			sumChargingKWH = reviewRecordData[index].sumChargingKWH;
		}
		$ajax('saveManualReview', {
							ChargingStationID: reviewRecordData[index].chargingStationID,
							SubBranchCompanyID: reviewRecordData[index].subBranchCompanyID,
							TeamID: reviewRecordData[index].teamID,
							LineID: reviewRecordData[index].lineID,
							TotalChargingKWH: totalChargingKWH,
							SumChargingKWH: sumChargingKWH,
							ChargingCount: reviewRecordData[index].chargingCount,
							ReviewPerson: $("#reviewPerson" + index).val(),
							ReviewState: 1,
							ReviewWay: reviewWay,
							Remarks: $("#remarks" + index).val(),
							ReviewDate: $("#startChargingTime").val().substring(0,10)
							}, saveData);
	}
}
function reviewStateNone(index) {
	if(!$("#startChargingTime").val()) {
		showMessge("时间错误，请刷新页面重试");
	} else if(!reviewLineIDData[index].chargingStationName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewLineIDData[index].lineName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewLineIDData[index].subBranchCompanyName) {
		showMessge("数据错误，请刷新页面重试");
	} else if(!reviewLineIDData[index].teamName) {
		showMessge("数据错误，请刷新页面重试");
	} else {
		indexFlag = index;
		var sumChargingKWH = 0;
		var reviewWay = "entering";
		var totalChargingKWH = 0;
		if($("#sumChargingKWHNone" + index).val()) {
			sumChargingKWH = $("#sumChargingKWHNone" + index).val();
		}
		$ajax('saveManualReview', {
							ChargingStationID: reviewLineIDData[index].chargingStationID,
							SubBranchCompanyID: reviewLineIDData[index].subBranchCompanyID,
							TeamID: reviewLineIDData[index].teamID,
							LineID: reviewLineIDData[index].lineID,
							TotalChargingKWH: totalChargingKWH,
							SumChargingKWH: sumChargingKWH,
							ChargingCount: reviewLineIDData[index].chargingCount,
							ReviewPerson: $("#reviewPersonNone" + index).val(),
							ReviewState: 1,
							ReviewWay: reviewWay,
							Remarks: $("#remarksNone" + index).val(),
							ReviewDate: $("#startChargingTime").val().substring(0,10)
							}, saveData);
	}
}
function saveData(data) {
	var result = data && data.result;
	if (result == "Success") {
		reviewMan = $("#reviewPerson" + indexFlag).val();
		var data =  {
				SubBranchCompanyID : reviewRecordData[indexFlag].subBranchCompanyID,
				TeamID : reviewRecordData[indexFlag].teamID,
				LineID : reviewRecordData[indexFlag].lineID,
				ChargingStationID : reviewRecordData[indexFlag].chargingStationID,
				StartChargingDate : $("#startChargingTime").val(),
				EndChargingDate : $("#endChargingTime").val()
				};
		$ajax('updateReviewState', data, updateReviewState);
	} else if (result == "collectionNameEmpty"){
		showMessge(messageContent["Insert.Failed"]);
	} else if (result == "error"){
		showMessge(messageContent["Insert.Failed"]);
	}
}
function updateReviewState(data){
	var result = data && data.result;
	if (result == "Success") {
		search();
//		$("#chargingKWH" + indexFlag).html(sumChargingKWH);
//		$("#remark" + indexFlag).html($("#remarks" + indexFlag).val());
//		$("#reviewFlag" + indexFlag).html("等待车队确认  <div class='HintImgDiv' onMouseOver='showHint(\""+ i +"\");' onMouseOut='hideHint(\""+ i +"\");'><img src='static/images/auditorHint.png'/>"
//				+ "<div class='auditorHintDiv' id='Hint"+ indexFlag +"div' hidden='hidden' onMouseOver='showHint(\""+ indexFlag +"\");' onMouseOut='hideHint(\""+ indexFlag +"\");'>" +
//						"<div class='HintTriangleOne'><div class='HintTriangleTwo'></div></div>" +
//						"<div class='HintMessage'>" +
//						"<div style='color:#c5c1c1'>车队负责人信息</div>" +
//						"<div id='Hint"+ indexFlag +"'>-</div>" +
//						"</div>" +
//						"</div>"
//		);
//		$("#reviewMan" + indexFlag).html($("#reviewPerson" + indexFlag).val());
//		$("#reviewState" + indexFlag).html('<span onclick="review('+ indexFlag +')" class="bacLightGreen details operationWord" style="color: white;">重新审核</span>');
//		$("#reviewFile" + indexFlag).html('<span onclick="upLoad('+ indexFlag +')" class="bacLightGreen details operationWord" style="color: white;">上传</span>');
	} else if (result == "SubBranchCompanyIDNull"){
		showMessge("未找到分公司！");
	} else if (result == "TeamIDNull"){
		showMessge("未找到车队！");
	} else if (result == "LineIDNull"){
		showMessge("未找到线路！");
	} else if (result == "StartChargingDateNull"){
		showMessge("时间错误！");
	} else if (result == "EndChargingDateNull"){
		showMessge("时间错误！");
	} else if (result == "NotFound"){
		showMessge(messageContent["Insert.Failed"]);
	} else {
		showMessge(messageContent["Insert.Error"]);
	}
}
function showHint(num){
	$("#Hint" + num + "div").show();
	HintNum = num;
	$ajax('searchUserInfo', {TeamID: reviewedRecordData[num].teamID, SubBranchCompanyID: reviewedRecordData[num].subBranchCompanyID}, searchHint, '', searchHint);
}
function hideHint(num){
	$("#Hint" + num + "div").hide();
}
function searchHint(data){
	var data = data && data.userInfo;
	if(data && data[0]) {
		$("#Hint" + HintNum).html(data[0].userName + ":" + data[0].phone);
	} else {
		$("#Hint" + HintNum).html("无车队人员信息");
	}
}
function review(index) {
	indexFlag = index;
	var data =  {
			ID: reviewedRecordData[index].id,
			SubBranchCompanyID : reviewedRecordData[indexFlag].subBranchCompanyID,
			TeamID : reviewedRecordData[indexFlag].teamID,
			LineID : reviewedRecordData[indexFlag].lineID,
			ChargingStationID : reviewedRecordData[indexFlag].chargingStationID,
			ReviewDate : reviewedRecordData[indexFlag].reviewDate,
			ReviewFile : reviewedRecordData[indexFlag].reviewFile,
			StartChargingDate : $("#startChargingTime").val(),
			EndChargingDate : $("#endChargingTime").val()
			};
	$ajax('deleteReviewState', data, deleteReviewState);
}
function deleteReviewState(data) {
	var result = data && data.result;
	if (result == "Success") {
		search();
	} else if (result == "LineIDNull"){
		showMessge("数据错误！");
	} else if (result == "StartChargingDateNull"){
		showMessge("时间错误！");
	} else if (result == "EndChargingDateNull"){
		showMessge("时间错误！");
	} else if (result == "NotFound"){
		showMessge("操作失败");
	} else {
		showMessge("操作异常");
	}
}
function save() {
	addTitle("manualReviewSave");
	createComBody("detailOneBody", lineReviewTable, null, 1);
	$("#save").modal("show");
	$ajaxList('subBranchCompany', getSubBranchCompany);
	$ajaxList('chargingStation', getChargingStation, {BulidStatus: '3'});
	$("#reviewPerson").val($("#userName", parent.document).html());
	$("#addReviewDate").val($("#startChargingTime").val().substring(0,10));
}
function getChargingStation(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#chargingStationID").append("<option value='" + data[i].chargingStationID + "'>" + data[i].chargingStationName + "</option>");
	}
}
function getSubBranchCompany(data) {
	$("#subBranchCompanyID").empty();
	$("#subBranchCompanyID").append("<option value=''>请选择</option>");
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#subBranchCompanyID").append("<option value='" + data[i].subBranchCompanyID + "'>" + data[i].subBranchCompanyName + "</option>");
	}
}
function changeSubBranchCompany(){
	var subBranchCompanyID = $("#subBranchCompanyID").val();
	if (subBranchCompanyID) {
		$("#teamID").empty();
		$("#teamID").append("<option value=''>请选择</option>");
		$ajaxList('carTeam', getCarTeam, {"subBranchCompanyID": subBranchCompanyID});
	} else {
		$("#teamID").empty();
		$("#lineID").empty();
	}
}
function getCarTeam(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#teamID").append("<option value='" + data[i].teamID + "'>" + data[i].teamName + "</option>");
	}
}
function changeTeam(){
	var teamID = $("#teamID").val();
	var subBranchCompanyID = $("#subBranchCompanyID").val();
	if (teamID) {
		$("#lineID").empty();
		$("#lineID").append("<option value=''>请选择</option>");
		$ajaxList('lineName', getLineName,{"teamID": teamID, "subBranchCompanyID": subBranchCompanyID});
	} else {
		$("#lineID").empty();
	}
}
function getLineName(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#lineID").append("<option value='" + data[i].lineID + "'>" + data[i].lineName + "</option>");
	}
}
function checkThis(){
	return checkForm("saveForm", lineReviewTable);
}
function saveManualReview(data) {
	var result = data && data.result;
	if (result == "Success") {
		$("#save").modal("hide");
		search();
	} else if (result == "ReviewedExist"){
		showMessge("审核信息已存在");
	} else if (result == "NotFound"){
		showMessge(messageContent["Insert.Failed"]);
	} else {
		showMessge(messageContent["Insert.Error"]);
	}
}
function upLoad(index) {
	indexFlag = index;
	$("#importFileForm").empty();
	$("#importFileForm").append('<input name="reviewDate" type="text" value="' + $("#startChargingTime").val().substring(0,10) + '" hidden/>');
	$("#importFileForm").append('<input name="chargingStationID" type="text" value="' + reviewedRecordData[index].chargingStationID + '" hidden/>');
	$("#importFileForm").append('<input name="lineID" type="text" value="' + reviewedRecordData[index].lineID + '" hidden/>');
	$("#importFileForm").append(
		'<div class="form-group" >'+
		'<label for="importFile" class="col-sm-3 control-label">电量凭证文件</label>' + 
		'<div class="col-sm-8"><input id="importFile" name="importFile" type="file" class="form-control"/></div>' + 
		'</div>'
	);
	var option = {
		showUpload: false,
		previewFileIcon: '<img src="static/images/icon-file.png" style="width:80px;height:80px;" />',
		showErrorPreview: false
	};
	selectFile("importFile", option);
	$("#fileinputModal").modal("show");
}
function confirm() {
	var importFile = $("#importFile").val();
	if (!importFile) {
		$("#importFile").tips({
			side : 2,
			msg : '请选择要上传的电量凭证文件',
			bg : '#AE81FF',
			time : 3
		});
		$("#importFile").focus();
	} else {
		showLoading();
		$ajaxSubmit('importFileForm', 'upLoadReviewFile', upLoadResult);
	}
}
function upLoadResult(data) {
	setTimeout(hideLoading, 500);
	$("#fileinputModal").modal("hide");
	var result = data && data.result;
	if (result == "Success") {
		showMessge("上传成功！");
		$("#reviewFile" + indexFlag).html('<span onclick="downLoad('+ indexFlag +')" class="bacLightGreen details operationWord" style="color: white;">查看</span>');
	} else if (result == "NotFound") {
		showMessge("上传失败，上传文件不存在！");
	} else {
		showMessge("上传异常，请重新选择文件 或 联系管理员！");
	}
}
function downLoad(index) {
	indexFlag = index;
	showMessge("确定下载吗?", "model2");
}
function sure(){
	showMessge("下载中......");
	var url = 'downLoadReviewFile?fileName=' + reviewedRecordData[indexFlag].reviewFile + '&&reviewDate=' + reviewedRecordData[indexFlag].reviewDate + '&&chargingStationID=' + reviewedRecordData[indexFlag].chargingStationID +
	'&&checkFlag=';
	$ajax(url, undefined, downLoadResult);
}
function downLoadResult(data){
	var result = data && data.result;
	if (result == "Success") {
		showLoading();
		var url = 'downLoadReviewFile?fileName=' + reviewedRecordData[indexFlag].reviewFile + '&&reviewDate=' + reviewedRecordData[indexFlag].reviewDate + '&&chargingStationID=' + reviewedRecordData[indexFlag].chargingStationID +
		'&&checkFlag=OK';
		downloadFile(url);
		showMessge("下载成功，文件正在生成！");
		setTimeout(hideLoading, 2000);
	} else if (result == "NotFound") {
		showMessge("下载失败，文件不存在!");
	} else {
		showMessge("下载失败，请重新下载 或 联系管理员！");
	}
}
function importFile(){
	$("#importForm").empty();
	$("#importForm").append(
		'<div class="form-group">'+
		'<label for="importExcle" class="col-sm-3 control-label">充电记录文件</label>' + 
		'<div class="col-sm-8"><input id="importExcle" name="importExcle" type="file" class="form-control"/></div>' + 
		'</div>'
	);
	var option = {
		allowedFileExtensions: ['xls', 'xlsx'],
		showUpload: false,
		previewFileIcon: '<img src="static/images/excel.png" style="width:80px;height:80px;" />',
		showErrorPreview: false
	};
	selectFile("importExcle", option);
	$("#importFileModal").modal("show");
}
function sureImport() {
	var importExcle = $("#importExcle").val();
	if (!importExcle) {
		$("#importFile").tips({
			side : 2,
			msg : '请选择要上传的手抄文件',
			bg : '#AE81FF',
			time : 3
		});
		$("#importFile").focus();
	} else {
		showLoading();
		$ajaxSubmit('importForm', 'importReviewRecord', importFileResult);
	}
}
function importFileResult(data) {
	setTimeout(hideLoading, 500);
	$("#importFileModal").modal("hide");
	var result = data && data.result;
	if (result == "Success") {
		var message = "导入成功";
		var count = data && data.count || 0;
		if (count > 0) {
			message = message + ", 其中有" + count + "条重复数据被更新";
		}
		showMessge(message + "！");
	} else if (result == "JsonError") {
		showMessge("导入失败，导入的JSON模板错误 或 不存在！");
	} else if (result == "NotFound") {
		showMessge("导入失败，文件不存在 或 文件内没有数据!");
	} else if (result == "ReviewDateNull") {
		showMessge("第" + data.index + "条数据日期为空！");
	} else if (result == "ChargingStationNull") {
		showMessge("第" + data.index + "条数据充电站为空！");
	} else if (result == "SubBranchCompanyNull") {
		showMessge("第" + data.index + "条数据分公司为空！");
	} else if (result == "TeamNameNull") {
		showMessge("第" + data.index + "条数据车队为空！");
	} else if (result == "LineNameNull") {
		showMessge("第" + data.index + "条数据线路为空！");
	} else if (result == "ChargingStationIDNull") {
		showMessge("充电站名称错误，请检查！");
	} else if (result == "SubBranchCompanyIDNull") {
		showMessge("分公司名称错误，请检查！");
	} else if (result == "TeamIDNull") {
		showMessge("车队名称错误，请检查！");
	} else if (result == "LineIDNull") {
		showMessge("线路名称错误，请检查！");
	} else {
		showMessge("导入异常，请重新选择文件 或 联系管理员！");
	}
}
function exportFile(){
	if (reviewedRecordData.length > 0) {
		var message = "确定导出吗?";
		showMessge(message, "model2");
	} else {
		showMessge("没有数据可导出！");
	}
}
function sure(){
	showMessge("导出中...");
	$ajaxCommon('exportReviewRecord?checkFlag=', exportFileResult);
}
function exportFileResult(data){
	var result = data && data.result;
	if (result == "Success") {
		downloadFile('exportReviewRecord?checkFlag=OK');
		showMessge("导出成功，审核数据文件正在生成！");
	} else if (result == "JsonError") {
		showMessge("导出失败，导出的JSON模板错误 或 不存在！");
	} else if (result == "NotFound") {
		showMessge("导出失败，没有数据可导出！");
	} else {
		showMessge("导出失败，请重新导出 或 联系管理员！");
	}
}